//
//  DestMoreCountryViewController.m
//  TravelEveryDay
//
//  Created by dlios on 15/10/16.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "DestMoreCountryViewController.h"
#import "BaseHeader.h"
#import "DestTabBarFourImageCollectionViewCell.h"
#import "DestTabBarModel.h"
#import "DestOtherCellInfoViewController.h"
#import "GiFHUD.h"
@interface DestMoreCountryViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property(strong,nonatomic)NSMutableArray *destModelArray;
@end

@implementation DestMoreCountryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    //数组初始化
    _destModelArray = [[NSMutableArray alloc]init];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame =CGRectMake(5, 20, 30, 30);
    [button setImage:[UIImage imageNamed:@"play-jiantouzuo.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(DestGoBack) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    //创建collectionView
    [self createCollectionView];
    //数据请求
    [self getDestMoreCountryData];
    
}
#pragma mark - 返回方法
- (void)DestGoBack {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 创建 collectionView的方法
- (void)createCollectionView {
    _destFlowLayout = [[UICollectionViewFlowLayout alloc]init];
    _destFlowLayout.itemSize = CGSizeMake(175 *WIDTH, 175 *WIDTH);
    _destFlowLayout.minimumInteritemSpacing = 5 * HEIGHT;
    _destFlowLayout.minimumLineSpacing = 5 * WIDTH;
    _destFlowLayout.sectionInset = UIEdgeInsetsMake(10 * WIDTH , 10 *WIDTH , 10  * WIDTH, 10 * WIDTH );
    _destTabBarCollectionView  = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT ) collectionViewLayout:_destFlowLayout];
    _destTabBarCollectionView.backgroundColor = [UIColor whiteColor];
    _destTabBarCollectionView.delegate = self;
    _destTabBarCollectionView.dataSource =self;
    _destTabBarCollectionView.showsHorizontalScrollIndicator = NO;
    [_destTabBarCollectionView registerClass:[DestTabBarFourImageCollectionViewCell class] forCellWithReuseIdentifier:@"destTabBarFourImageCollectionViewCell"];
    [self.view addSubview:_destTabBarCollectionView];
}
#pragma mark - collectionView的代理方法 : 返回row个数
- (NSInteger )collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _destModelArray.count;
}
#pragma mark - collectionView的代理方法 :返回cell类型
- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    DestTabBarFourImageCollectionViewCell  *destTabBarcell = [collectionView dequeueReusableCellWithReuseIdentifier:@"destTabBarFourImageCollectionViewCell" forIndexPath:indexPath];
    DestTabBarModel *destMoreCountryModel = [_destModelArray objectAtIndex:indexPath.row];
    //传值属性;
    destTabBarcell.destMoreCountryModel = destMoreCountryModel;
    return destTabBarcell;
}
#pragma mark - 数据请求的方法
- (void)getDestMoreCountryData {
    //皮卡丘
    
    
    
    [DestAFNDataBlock string:[NSString stringWithFormat:@"http://api.breadtrip.com/destination/index_places/%@/",_index] AFNData:^(id block) {
        NSMutableDictionary *jsonDic = block;
        NSMutableArray *dataArray = [jsonDic objectForKey:@"data"];
        //数据处理
        for (NSMutableDictionary *dataDic in dataArray) {
            DestTabBarModel *tabBarModel =[DestTabBarModel modelWithDictionary:dataDic];
            [_destModelArray addObject:tabBarModel];
        }
        self.title = [jsonDic objectForKey:@"title"];

        [_destTabBarCollectionView reloadData];
    } AFNData1:^(id block) {
        [GiFHUD dismiss];
    }];
}
#pragma mark - collectionView点击方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    DestOtherCellInfoViewController *otherCell = [[DestOtherCellInfoViewController alloc]init];
    DestTabBarModel *destMoreCountryModel = [_destModelArray objectAtIndex:indexPath.row];
    otherCell.type = destMoreCountryModel.type;
    otherCell.MyId = destMoreCountryModel.MyId;
    [self.navigationController pushViewController:otherCell animated:YES];
}
-(void)viewWillAppear:(BOOL)animated {
    self.navigationController.navigationBarHidden = NO;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
